import coin.exchange.base.kr_rest.native_public_client_base as npubcb


class BinanceFuturesNativePublicClient(npubcb.NativePublicClientBase):
  def __init__(self):
    npubcb.NativePublicClientBase.__init__(self, url="https://dapi.binance.com/dapi/v1")
    self._valid_kline_period = [
        '1m', '3m', '5m', '15m', '30m', '1h', '2h', '4h', '6h', '8h', '12h', '1d', '3d', '1w', '1M'
    ]

  def check_kline_period(self, kline_period):
    assert kline_period in self._valid_kline_period, \
        'Invalid kline period!'

  def get_history_kline(self, symbol, kline_period, limit=None, start_time=None, end_time=None):
    self.check_kline_period(kline_period)
    url = "klines"
    params = {
        'symbol': symbol,
        'interval': kline_period,
        'limit': limit,
        'startTime': (int(start_time.timestamp() * 10**3) if start_time else None),
        'endTime': (int(end_time.timestamp() * 10**3) if end_time else None)
    }
    return self._get_as_json(url, params)

  def queryAll(self):
    raise NotImplementedError()
